package com.service.Impl;

import com.Dao.BookDao;
import com.entity.Book;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.BookService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookServiceImpl implements BookService{
    @Resource
    private BookDao bookDao;

    @Override
    public PageInfo<Book> findAllBook(String title,String author, int pageNum) {
        Book book=new Book();
        book.setTitle(title);
        book.setAuthor(author);
        //设置当前页，页面容量
        PageHelper.startPage(pageNum,5);
        List<Book> list=bookDao.findAllBook(book);
        PageInfo<Book> pageInfo=new PageInfo<Book>(list);
        if(pageInfo.getList().size()>0)
        {
            return pageInfo;
        }else{
            return null;
        }
    }

    @Override
    public int saveBook(Book book) {
        return bookDao.saveBook(book);
    }

    @Override
    public Integer deleteBook(int id) {
        return bookDao.deleteBook(id);
    }


    @Override
    public Book getBook(int id) {
        return bookDao.getBook(id);
    }

    @Override
    public void updateBook(Book book) {
        bookDao.updateBook(book);
    }

    @Override
    public Book selectBookById(int id){
        return bookDao.selectBookById(id);
    }

}
